<template>
    <div>
        <div style="display: flex; border: 1px solid #f2f2f2">
            <div class="namebox">
                <span style="white-space: nowrap">发明人信息</span>
            </div>
            <div style="padding: 10px">
                <el-button
                    v-perms="['linkman:add']"
                    size="small"
                    type="primary"
                    @click="handleAdd()"
                >
                    <template #icon>
                        <icon name="el-icon-Plus" />
                    </template>
                    添加发明人
                </el-button>
                <el-table class="mt-4" style="width: 90%" size="large" v-loading="pager.loading" :data="pager.lists" stripe>
                    <el-table-column type="selection" width="55" />
                    <el-table-column label="ID" prop="id" min-width="50" />

                    <el-table-column label="客户名称" prop="customerName" min-width="110">
                        <template #default="{ row }">
                            <span @click="handleEditcopy(row)" style="color: #409eff">
                                {{ row.customerName }}</span
                            >
                        </template>
                    </el-table-column>
                    <el-table-column label="姓名" prop="chineseName" min-width="110" />
                    <el-table-column label="英文名" prop="englishName" min-width="100" />
                    <el-table-column label="国别(地区)" prop="nation" min-width="110" />
                    <el-table-column label="地址(英文)" prop="nation" min-width="110" />
                    <el-table-column label="身份证号" prop="idNumber" min-width="110" />
                    <el-table-column label="工号" prop="idNumber" min-width="110" />
                    <el-table-column label="联系电话" prop="phone" min-width="110" />
                    <el-table-column label="邮件" prop="email" min-width="110" />
                    <el-table-column label="创建时间" prop="createTime" min-width="100" />
                    <el-table-column label="创建人员" prop="creator" min-width="100" />
                    <el-table-column label="操作" width="120" fixed="right">
                        <template #default="{ row }">
                            <!-- <el-button v-perms="['inventor:edit']" type="primary" link @click="handleEdit(row)">
                                编辑
                            </el-button> -->
                            <el-button
                                v-perms="['inventor:del']"
                                type="danger"
                                link
                                @click="handleDelete(row.id)"
                            >
                                删除
                            </el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <edit-popup
                v-if="showEdit"
                ref="editRef"
                @success="getLists"
                @close="showEdit = false"
            />
            <editcopy
                v-if="copyEdit"
                ref="editCopy"
                @success="getLists"
                @close="copyEdit = false"
            />
        </div>
    </div>
</template>

<script lang="ts" setup>
import { inventorDelete, inventorLists } from '@/api/inventor'
import { usePaging } from '@/hooks/usePaging'
import feedback from '@/utils/feedback'
import EditPopup from './inventorEdit.vue'
import editcopy from './inventorEdit copy.vue'

const editRef = shallowRef<InstanceType<typeof EditPopup>>()
const editCopy = shallowRef<InstanceType<typeof editcopy>>()
const showEdit = ref(false)
const copyEdit = ref(false)
const queryParams = reactive({
    customerName: '',
    chineseName: '',
    englishName: '',
    idNumber: '',
    creatorTimeStart: '',
    creatorTimeEnd: ''
})

const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: inventorLists,
    params: queryParams
})

const handleAdd = async () => {
    showEdit.value = true
    await nextTick()
    editRef.value?.open('add')
}

const handleEdit = async (data: any) => {
    showEdit.value = true
    await nextTick()
    editRef.value?.open('edit')
    editRef.value?.getDetail(data)
}
const handleEditcopy = async (data: any) => {
    copyEdit.value = true
    await nextTick()
    editCopy.value?.open('edit')
    editCopy.value?.getDetail(data)
}

const handleDelete = async (id: number) => {
    await feedback.confirm('确定要删除？')
    await inventorDelete({ id })
    feedback.msgSuccess('删除成功')
    getLists()
}

getLists()
</script>

<style>
.namebox {
    /* padding: 0px 50px; */
    min-width: 175px;
    background-color: var(--el-bg-color-collapse);
    display: flex;
    justify-content: center;
    align-items: center;
}
</style>
